<?
include("../lib/config.php");
$nik 	= $HTTP_GET_VARS['nik'];
$op		= $HTTP_GET_VARS['op'];
$no		= $HTTP_GET_VARS['no'];
$id		= $HTTP_GET_VARS['id'];

if($op == "edit"){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("SELECT A.*, B.nama FROM S_LP A, Karyawan B WHERE A.id='$id' AND A.NIK=B.NIK",$conn);
	$row	= mssql_fetch_array($query);
	$read	= "readonly";
	$dis	= "disabled";
}
else{
	$Faction = "../lib/save.php";
	$Vbutton = "Simpan";
}

include("../header.php");
?>
<script type="text/javascript">
	
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};


	function Validate(){

		if(document.forms[0].nik.value == ""){
			alert("Maaf, NIK tidak boleh kosong ...");
			document.forms[0].nik.focus();
			return false;
		}
		
		if(document.forms[0].tahun.value == ""){
			alert("Maaf, Tahun tidak boleh kosong ...");
			document.forms[0].tahun.focus();
			return false;
		}
		
		if(document.forms[0].nik_atasan1.value == ""){
			alert("Maaf, NIK Penilai Atasan I tidak boleh kosong ...");
			document.forms[0].nik_atasan1.focus();
			return false;
		}
		
		if(document.forms[0].nik_atasan2.value == ""){
			alert("Maaf, NIK Penilai Atasan II tidak boleh kosong ...");
			document.forms[0].nik_atasan2.focus();
			return false;
		}
		
		if(document.forms[0].nik_peers1.value == ""){
			alert("Maaf, NIK Penilai Peers (Rekan Kerja) I tidak boleh kosong ...");
			document.forms[0].nik_peers1.focus();
			return false;
		}
		
		if(document.forms[0].nik_peers2.value == ""){
			alert("Maaf, NIK Penilai Peers (Rekan Kerja) II tidak boleh kosong ...");
			document.forms[0].nik_peers2.focus();
			return false;
		}
		
		if(document.forms[0].nik_peers3.value == ""){
			alert("Maaf, NIK Penilai Peers (Rekan Kerja) III tidak boleh kosong ...");
			document.forms[0].nik_peers3.focus();
			return false;
		}

		if(document.forms[0].nik_adum.value == ""){
			alert("Maaf, NIK Penilai Adum tidak boleh kosong ...");
			document.forms[0].nik_adum.focus();
			return false;
		}
		
		document.forms[0].submit();
	}

	
	function show_popup(page)
	{
		child = open
		(
			"frm_list_emp.php",
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}

	function show_popup2(N)
	{
		child = open
		(
			"frm_list_emp_other.php?n="+N+"",
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}
</script>
</head>
<table width="93%" class="table_indent2">
 <tr>
  <td class="line_bottom">&nbsp;&nbsp;<b>PENILAIAN KARYAWAN</b></td>
 </tr>
</table>
<form method="POST" action="<?=$Faction?>">
<table width="100%">
 <tr>
  <td colspan="2">
  	&nbsp;<b>Masukkan Pegawai yang akan dinilai:</b>
   <table>
    <tr>
	 <td width="110">NIK</td>
	 <td><input type="text" name="nik" value="<?=$row[NIK]?>" readonly=""/>
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup()'><img src='../images/people.png' border=0></a>";
		}
	?>
	 </td>
	</tr>
    <tr>
	 <td>Nama</td>
	 <td><input type="text" name="nama" value="<?=$row[nama]?>" size="45" readonly="" /></td>
	</tr>
    <tr>
	 <td>Tahun Periode</td>
	 <td>
	 <select name="tahun">
	  <option value="">--pilih--</option>
	  <?
	  	for($i=1980; $i<=2100; $i++){
			echo"<option value='$i'";
			if($op == "edit"){
				if($i == $row[periode]){
					echo" selected";
				}
			}
			else{
				if($i == date("Y")){
					echo" selected";
				}
			}
			echo">$i</i>";
		}
	  ?>
	 </select>
	 </td>
	</tr>
   </table>
  </td>
 </tr>
 <tr>
  <td colspan="2">
	<fieldset>
     <legend>Penilai Atasan</legend>
  <table>
    <tr>
     <td colspan="2"><b><i>Penilai I</td>
    </tr>
    <tr>
	 <td width="110">NIK</td>
	 <td><input type="text" name="nik_atasan1" value="<?=$row[penilai_atasan1]?>" readonly=""/>
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup2(\"nik_atasan1\")'><img src='../images/people.png' border=0></a>";
		}
	?>
	 </td>
	</tr>
    <?
    // get nama penilai atasan 1
	$sgn1 = mssql_query("SELECT Nama FROM Karyawan WHERE NIK='$row[penilai_atasan1]'",$conn);
	$rgn1 = mssql_fetch_array($sgn1);
	?>
    <tr>
	 <td>Nama</td>
	 <td><input type="text" name="nama_atasan1" value="<?=$rgn1[Nama]?>" size="45" readonly="" /></td>
	</tr>
    <tr>
     <td colspan="2"><b><i>Penilai II</td>
    </tr>
    <?
    // get nama penilai atasan 2
	$sgn2 = mssql_query("SELECT Nama FROM Karyawan WHERE NIK='$row[penilai_atasan2]'",$conn);
	$rgn2 = mssql_fetch_array($sgn2);
	?>
    <tr>
	 <td width="110">NIK</td>
	 <td><input type="text" name="nik_atasan2" value="<?=$row[penilai_atasan2]?>" readonly=""/>
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup2(\"nik_atasan2\")'><img src='../images/people.png' border=0></a>";
		}
	?>
	 </td>
	</tr>
    <tr>
	 <td>Nama</td>
	 <td><input type="text" name="nama_atasan2" value="<?=$rgn2[Nama]?>" size="45" readonly="" /></td>
	</tr>
  </table>
  </fieldset>
  </td>
 </tr>
 <tr>
  <td colspan="2">
	<fieldset>
     <legend>Penilai Peers (Rekan Kerja)</legend>
  <table>
    <tr>
     <td colspan="2"><b><i>Penilai I</td>
    </tr>
    <?
    // get nama penilai peers 1
	$sgn3 = mssql_query("SELECT Nama FROM Karyawan WHERE NIK='$row[penilai_peers1]'",$conn);
	$rgn3 = mssql_fetch_array($sgn3);
	?>
    <tr>
	 <td width="110">NIK</td>
	 <td><input type="text" name="nik_peers1" value="<?=$row[penilai_peers1]?>" readonly=""/>
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup2(\"nik_peers1\")'><img src='../images/people.png' border=0></a>";
		}
	?>
	 </td>
	</tr>
    <tr>
	 <td>Nama</td>
	 <td><input type="text" name="nama_peers1" value="<?=$rgn3[Nama]?>" size="45" readonly="" /></td>
	</tr>
    <tr>
     <td colspan="2"><b><i>Penilai II</td>
    </tr>
    <?
    // get nama penilai peers 2
	$sgn4 = mssql_query("SELECT Nama FROM Karyawan WHERE NIK='$row[penilai_peers2]'",$conn);
	$rgn4 = mssql_fetch_array($sgn4);
	?>
    <tr>
	 <td width="110">NIK</td>
	 <td><input type="text" name="nik_peers2" value="<?=$row[penilai_peers2]?>" readonly=""/>
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup2(\"nik_peers2\")'><img src='../images/people.png' border=0></a>";
		}
	?>
	 </td>
	</tr>
    <tr>
	 <td>Nama</td>
	 <td><input type="text" name="nama_peers2" value="<?=$rgn4[Nama]?>" size="45" readonly="" /></td>
	</tr>
    <tr>
     <td colspan="2"><b><i>Penilai III</td>
    </tr>
    <?
    // get nama penilai peers 2
	$sgn5 = mssql_query("SELECT Nama FROM Karyawan WHERE NIK='$row[penilai_peers3]'",$conn);
	$rgn5 = mssql_fetch_array($sgn5);
	?>
    <tr>
	 <td width="110">NIK</td>
	 <td><input type="text" name="nik_peers3" value="<?=$row[penilai_peers3]?>" readonly=""/>
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup2(\"nik_peers3\")'><img src='../images/people.png' border=0></a>";
		}
	?>
	 </td>
	</tr>
    <tr>
	 <td>Nama</td>
	 <td><input type="text" name="nama_peers3" value="<?=$rgn5[Nama]?>" size="45" readonly="" /></td>
	</tr>
  </table>
  </fieldset>
  </td>
 </tr>
 <tr>
  <td colspan="2">
	<fieldset>
     <legend>Penilai Adum (Administrasi Umum Kepegawaian)</legend>
  <table>
    <tr>
	 <td width="110">NIK</td>
	 <td><input type="text" name="nik_adum" value="<?=$row[penilai_adum]?>" readonly=""/>
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup2(\"nik_adum\")'><img src='../images/people.png' border=0></a>";
		}
	?>
	 </td>
	</tr>
    <?
    // get nama penilai atasan 1
	$sgn6 = mssql_query("SELECT Nama FROM Karyawan WHERE NIK='$row[penilai_adum]'",$conn);
	$rgn6 = mssql_fetch_array($sgn6);
	?>
    <tr>
	 <td>Nama</td>
	 <td><input type="text" name="nama_adum" value="<?=$rgn6[Nama]?>" size="45" readonly="" /></td>
	</tr>
  </table>
  </fieldset>
  </td>
 </tr>
 <tr>
  <td>&nbsp;</td>
  <td align="left"><br />
  <input type="hidden" name="cat" value="LP" />
  <input type="hidden" name="id" value="<?=$id?>" />
  <input type="button" value="Batal" class="button" onclick="Javascript:history.back();" />
  <input type="button" value="<?=$Vbutton?>" class="button" onclick="Javascript:Validate();" />
  </td>
 </tr>
</table>
</form>
</td>
</tr>
</table>
</body>
<script type="text/javascript">

var f = document.forms[0];
MaskInput(f.tahun,"9999");
//]]>
</script>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>
